package com.osdp.uc.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.osdp.common.util.BeansUtil;
import com.osdp.common.util.ConvertUtil;
import com.osdp.uc.entity.UcOrgType;
import com.osdp.uc.mapper.UcOrgTypeMapper;
import com.osdp.uc.service.IUcOrgTypeService;
import com.osdp.uc.util.Fields;
import com.osdp.uc.vo.UcOrgTypeVo;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UcOrgTypeServiceImpl extends ServiceImpl<UcOrgTypeMapper, UcOrgType> implements IUcOrgTypeService {

//    @Autowired
//    private UcOrgTypeMapper orgTypeMapper;

    @Override
    public IPage<UcOrgTypeVo> pageList(UcOrgTypeVo ucOrgTypeVo, Page<UcOrgType> page) {
        return super.page(page, new QueryWrapper<UcOrgType>()
                .like(StringUtils.isNotBlank(ucOrgTypeVo.getTypeCode()), Fields.UcOrgTypeQ.typeCode,ucOrgTypeVo.getTypeCode())
                .like(StringUtils.isNotBlank(ucOrgTypeVo.getTypeName()), Fields.UcOrgTypeQ.typeName,ucOrgTypeVo.getTypeName())
                        .orderByAsc(Fields.UcOrgTypeQ.sortNo))
                .convert(track -> BeansUtil.copy(track, new UcOrgTypeVo()));
    }

    @Override
    public List<UcOrgTypeVo> queryList(UcOrgTypeVo ucOrgTypeVo){
        List<UcOrgType> list = super.list(new QueryWrapper<UcOrgType>()
                .like(StringUtils.isNotBlank(ucOrgTypeVo.getTypeCode()), Fields.UcOrgTypeQ.typeCode,ucOrgTypeVo.getTypeCode())
                .like(StringUtils.isNotBlank(ucOrgTypeVo.getTypeName()), Fields.UcOrgTypeQ.typeName,ucOrgTypeVo.getTypeName())
                .orderByAsc(Fields.UcOrgTypeQ.sortNo)
        );
        return ConvertUtil.sourceToTarget(list, UcOrgTypeVo.class);
    }
}
